package com.asteroid20.loginsystem.controller;

import com.asteroid20.loginsystem.service.UserService;
import com.asteroid20.loginsystem.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

@Controller
public class controllertest {

    @Autowired
    private UserService userService;

    @GetMapping("/")
    public String homePage(){
//        List<User> user = userService.findAllUser();
//        model.addAttribute("user",user);
        return "register";
    }
    @GetMapping("test")
    public String test(){
        return "test";
    }
    @GetMapping("reg")
    public String add(Model model){

        model.addAttribute("user",new User());
        System.out.println("shijianxing");
        return "reg";
    }
    @GetMapping("register")
    public String add2(Model model){

        model.addAttribute("user",new User());
        System.out.println("register");
        return "register";
    }
    @PostMapping("/registration")
    public String registerUser(User user){

        userService.saveUser(user);
        System.out.println("已注册");
        return "redirect:/test";
    }
}
